home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DBASE_UT / TPDB335 / MAKEINC.PAS < prev    next >
Pascal/Delphi Source File  |  1993-11-26  |  3KB  |  86 lines

  1. program makeinc;
  2.  
  3.                            (***********************************)
  4.                            (*               TPDB              *)
  5.                            (***********************************)
  6.                            (*         Object -Oriented        *)
  7.                            (*    Borland/Turbo Pascal Units   *)
  8.                            (*    for Accessing dBASE III      *)
  9.                            (*             files.              *)
  10.                            (*      Copyright 1988 - 1993      *)
  11.                            (*          Brian Corll            *)
  12.                            (*       All Rights Reserved       *)
  13.                            (***********************************)
  14.                            (*            FREEWARE             *)
  15.                            (***********************************)
  16.                            (*     dBASE is a registered       *)
  17.                            (* trademark of Borland Int. Inc.  *)
  18.                            (*   Version 3.35  November, 1993  *)
  19.                            (***********************************)
  20.                            (*   Portions Copyright 1984,1991  *)
  21.                            (*    Borland International Corp.  *)
  22.                            (***********************************)
  23.  
  24. {
  25.   Syntax: MAKEINC filename.dbf filename.inc
  26.   Do not append a path to the file names.
  27.  
  28.   This little utility allows you to create a small constants declaration
  29.   file from a DBF file header.  Use of the declarations file simplifies
  30.   calls to field-level routines. For  example, the following constants file
  31.   was created by this program from customer.dbf:
  32.   const
  33.    COMPANY    =   1
  34.    ADDRESS1   =   2
  35.    ADDRESS2   =   3
  36.    CITY       =   4
  37.    STATE      =   5
  38.    ZIP        =   6
  39.  
  40.    When accessing fields, as in the Repl procedure, the required field
  41.    number may be replaced by the constant, as in
  42.       Repl(COMPANY,'SoftIron');
  43.    }
  44.  
  45.  
  46. uses tpdb,tpdbstr;
  47.  
  48. var dbf : dataobject;
  49.     constfile : text;
  50.     f : byte;
  51.     root : string[8];
  52.  
  53.     procedure writefieldname(fno : byte);
  54.     var c : byte;
  55.         fname : string[10];
  56.     begin
  57.       fillchar(fname,10,#0);
  58.       fname[0] := #10;
  59.       for c := 1 to 11 do
  60.          if dbf^.fields^[fno].fieldname[c] <> #0 then
  61.             fname[c] :=  dbf^.fields^[fno].fieldname[c]
  62.          else
  63.          begin
  64.             dec(c);
  65.             fname[0] := chr(c);
  66.             write(constfile,'   '+root+'_'+padr(fname,10));
  67.             exit;
  68.          end;
  69.     end;
  70.  
  71. begin
  72.    root := copy(paramstr(1),1,pos('.',paramstr(1))-1);
  73.    new(dbf,init(paramstr(1)));
  74.    assign(constfile,paramstr(2));
  75.    rewrite(constfile);
  76.    writeln(constfile,'const');
  77.    with dbf^ do
  78.    for f := 1 to numfields do
  79.    begin
  80.       writefieldname(f);
  81.       writeln(constfile,' = ',f:3,';');
  82.    end;
  83.    dbf^.done;
  84.    close(constfile);
  85. end.
  86.